<?php

namespace Gwit\PlateformBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Gwit\PlateformBundle\Entity\Author;
use Symfony\Component\HttpFoundation\Response;


class DefaultController extends Controller
{
    
    public function indexAction($name)
    {
        return $this->render('GwitPlateformBundle:Default:index.html.twig', array('name' => $name));
    }
    
    public function renderlayoutAction(){
        return $this->render('GwitPlateformBundle:LayoutComponent:layout.html.twig');
    }
    
    public function testmailAction(){
        $message = \Swift_Message::newInstance()
                ->setSubject('Hello Email')
                ->setFrom('nourdinm@yahoo.fr')
                ->setTo('nourdinm@yahoo.fr')
                ->setBody($this->renderView('GwitPlateformBundle:otherdoc:emailconfirm.txt.twig'));
        $this->get('mailer')->send($message);
        
        return $this->redirect($this->generateUrl('GwitPlateformBundle_homepage', array('name' => 'Mail sended')));
    }
    
    public function testvalidatorAction(){
        $author = new Author();
        
        $validator = $this->get('validator');
        $errors = $validator->validate($author);

        if (count($errors) > 0) {
            return new Response(print_r($errors, true));
        } else {
            return new Response('The author is valid! Yes!');
        }
    }
    
    public function testlayoutAction()
    {
        return $this->render('GwitPlateformBundle:otherdoc:layoutTestGUI.html.twig');
    }
}
